#include "zoomer.h"
#include <QDebug>
#include <QImage>
#include <QHBoxLayout>

Zoomer::Zoomer(QWidget *parent) :
    QWidget(parent)
{
    imageLabel = new QLabel;
    imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    imageLabel->setScaledContents(true);

    scrollArea = new QScrollArea(parent);
    scrollArea->setWidget(imageLabel);

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(scrollArea);
    setLayout(layout);

    scale = 1;
}

void Zoomer::updateScale(double d)
{
    scale = d;
    scaleImage();
}

void Zoomer::loadNewImage(QString fileName)
{
    QImage image(fileName);
    if(!image.isNull())
    {
        qDebug()<<"Wczytano";
        imageLabel->setPixmap(QPixmap::fromImage(image));
        scaleImage();
    }
}

QImage Zoomer::getImage()
{
    return imageLabel->pixmap()->toImage();
}


void Zoomer::scaleImage()
{
    imageLabel->resize(scale * imageLabel->pixmap()->size());
}
